package rexsee.core.utilities;

import rexsee.core.browser.Browser;
import rexsee.core.browser.clazz.JavascriptInterface;

public class RexseeUtilities implements JavascriptInterface {

	public static final String INTERFACE_NAME = "Utilities";
	@Override
	public String getInterfaceName() {
		return mBrowser.application.resources.prefix + INTERFACE_NAME;
	}
	@Override
	public JavascriptInterface getInheritInterface(Browser childBrowser) {
		return this;
	}
	@Override
	public JavascriptInterface getNewInterface(Browser childBrowser) {
		return new RexseeUtilities(childBrowser);
	}

	private final Browser mBrowser;
	public RexseeUtilities(Browser browser) {
		mBrowser = browser;
	}

	//JavaScript interface
	public String getMimeType(String url) {
		return Utilities.getMime(url);
	}
	public String base64encode(String text, String encoding) {
		try {
			return new String(Base64.encode(text.getBytes(encoding)));
		} catch (Exception e) {
			return null;
		}
	}
	public String base64decode(String text, String encoding) {
		try {
			return new String(Base64.decode(text), encoding);
		} catch (Exception e) {
			return null;
		}
	}
	public String md5(String plainText, boolean is32) {
		return Utilities.md5(plainText, is32);
	}

}
